﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WirteFile
{
    internal class Program
    {

        static void Main(string[] args)
        {
            byte[] byteData;
            char[] charData;

            try
            {
                FileStream afile = new FileStream("Temp.txt", FileMode.Create);
                charData="我的第一个程序" .ToCharArray();
                byteData=new byte[charData.Length*2];
                Encoder e = Encoding.Default.GetEncoder();
                e.GetBytes(charData, 0, charData.Length, byteData, 0, true);
                afile.Seek(0, SeekOrigin.Begin);
                afile.Write(byteData, 0, byteData.Length);
            }
            catch (Exception a)
            {
                Console.WriteLine(a.Message);
                Console.ReadKey();
                return;
                
            }


        }
    }
}
